﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using RM2012Server.Model;
using System.IO;

namespace RM2012Server.View
{
    public partial class frmLog : Office2007Form
    {
        public Log log;

        public frmLog()
        {
            InitializeComponent();
        }

        private void frmLog_Load(object sender, EventArgs e)
        {
            log = new Log();
            DateTime today = DateTime.Now;
            if (today.Day < 10)
            {
                txtDay.Text = "0" + today.Day.ToString();
            }
            else
            {
                txtDay.Text = today.Day.ToString();
            }
            if (today.Month < 10)
            {
                txtMonth.Text = "0" + today.Month.ToString();
            }
            else
            {
                txtMonth.Text = today.Month.ToString();
            }
            txtYear.Text = today.Year.ToString();
        }

        private void monthCalendarAdv_ItemClick(object sender, EventArgs e)
        {
            DateTime dt = monthCalendarAdv.SelectedDate;
            if (dt.Day < 10)
            {
                txtDay.Text = "0" + dt.Day.ToString();
            }
            else
            {
                txtDay.Text = dt.Day.ToString();
            }
            if (dt.Month < 10)
            {
                txtMonth.Text = "0" + dt.Month.ToString();
            }
            else
            {
                txtMonth.Text = dt.Month.ToString();
            }
            txtYear.Text = dt.Year.ToString();
            ViewLogFile();
        }

        private void btnViewLog_Click(object sender, EventArgs e)
        {
            ViewLogFile();
        }

        private void btnDeleteLog_Click(object sender, EventArgs e)
        {
            try
            {

            }
            catch
            {
            	
            }
        }

        public void ViewLogFile()
        {
            try
            {
                String _fileName = "Log_" + txtYear.Text + txtMonth.Text + txtDay.Text + ".txt";
                if (log.IsExistFile(_fileName))
                {
                    rtxtContent.Text = log.ViewLog(_fileName);
                }
                else
                {
                    rtxtContent.Text = "Không tồn tại nhật ký ngày " + txtDay.Text + "/" + txtMonth.Text + "/" + txtYear.Text + ".";
                }
            }
            catch (Exception ex)
            {
                rtxtContent.Text = ex.Message;
            }
        }
    }
}
